package com.ruoyi.coffee.controller;
import com.ruoyi.coffee.domain.ShopCarts;
import com.ruoyi.coffee.dto.ShopCartDto;
import com.ruoyi.coffee.service.IShopCartsService;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author dxj
 * @Description 购物车接口
 * @date 2025/2/10 21:45
 */
@RestController
@RequestMapping("/shopCart")
@AllArgsConstructor
@Slf4j
@Api(tags = "购物车")
public class ShopCartsController {
    private final IShopCartsService shopCartsService;
    @GetMapping("/list")
    @ApiOperation(value = "用户购物车列表", notes = "用户购物车列表")
    public AjaxResult getShopCartsList() {
        return shopCartsService.getShopList();
    }

    @PostMapping("/save")
    @ApiOperation(value = "加入购物车", notes = "商品加入购物车")
    public AjaxResult saveShopCarts(@RequestBody ShopCartDto shopCartDto) {
        log.info("加入购物车参数：{}", shopCartDto);
        return shopCartsService.saveShopCarts(shopCartDto);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改购物车", notes = "修改购物车")
    public AjaxResult updateShopCarts(@RequestBody ShopCartDto shopCartDto) {
        log.info("修改购物车参数：{}", shopCartDto);
        return shopCartsService.updateShopCartsInfo(shopCartDto);
    }
    @PostMapping("/removeAll")
    @ApiOperation(value = "清空购物车", notes = "清空购物车")
    public AjaxResult removeAll(@RequestBody Map<String, Long[]> request) {
        Long[] ids = request.get("ids");
        return shopCartsService.removeAllByIds(ids);
    }
}
